package com.se7en.ufutil;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

public class Trash extends Overlay {
	TrashModel[] currentBins;
	Context ctx;
	DataAccess dataAccess;
	static Bitmap trashMarker, paperRecycleMarker, plasticRecycleMarker;
	public Trash(Context inContext, DataAccess dataAccess)
	{
		ctx = inContext;
		this.dataAccess = dataAccess;
		currentBins = dataAccess.getAllTrashModels();
		trashMarker = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.trash);
		paperRecycleMarker = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.paper_recycle);
		plasticRecycleMarker = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.plastic_recycle);
	}
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow)
	{
		super.draw(canvas, mapView, shadow);
		if(currentBins.length < 1) return;
		for(TrashModel bin : currentBins)
		{
			// Adlai: Where are we going to draw the next marker?
			Point nextDrawingPoint = new Point();
			mapView.getProjection().toPixels(bin.location, nextDrawingPoint);
			// Adlai: What are we going to draw?
			Bitmap nextDrawingImage;
			switch(bin.type)
			{
			case TRASH:
				nextDrawingImage = trashMarker;
				break;
			case RECYCLE_PAPER:
				nextDrawingImage = paperRecycleMarker;
				break;
			case RECYCLE_PLASTIC:
				nextDrawingImage = plasticRecycleMarker;
				break;
			default:
				nextDrawingImage = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.error);
				break;
			}
			// Adlai: Let's draw!
			canvas.drawBitmap(nextDrawingImage, nextDrawingPoint.x, nextDrawingPoint.y, null);
		}
		return;
	}
}